﻿namespace Numbrella.TaskSamples.PrimeNumbers
{
	using System;
	using Numbrella.Core;
	
	[Serializable]
	public class Task : TaskBase<ResultContents>
	{
		private readonly long rangeStart;

		private readonly long rangeEnd;

		public Task(long rangeStart, long rangeEnd, int id)
			: base(id)
		{
			this.rangeStart = rangeStart;
			this.rangeEnd = rangeEnd;
		}

		#region Methods

		protected override ResultContents ReallyPerform()
		{
			long result = 0;
			for (long number = this.rangeStart; number <= this.rangeEnd; ++number)
			{
				bool isPrime = true;

				for (long divider = 2; divider * divider <= number; ++divider)
					if (number % divider == 0)
					{
						isPrime = false;
						break;
					}

				if (isPrime)
					++result;
			}

			return new ResultContents(result);
		}

		#endregion
	}
}
